package com.mti.epivisitemobile.view
{
	import com.mti.epivisitemobile.Constants;
	
	import flash.events.MouseEvent;
	
	import mx.events.FlexEvent;
	
	import org.puremvc.as3.patterns.mediator.Mediator;
	
	public class HomeViewMediator extends Mediator
	{
		public static const NAME:String = "HomeViewMediator";
		
		// #region Constructor
		
		/**
		 * HomeViewMediator constructor.
		 */
		public function HomeViewMediator(viewComponent:HomeView)
		{
			super(NAME, viewComponent);
			
			// Wait for the view creation to be completed
			viewComponent.addEventListener(FlexEvent.CREATION_COMPLETE, handleViewCreated);
		}
		
		private function handleViewCreated(evt:FlexEvent):void
		{
			view.removeEventListener(FlexEvent.CREATION_COMPLETE, handleViewCreated);
			
			view.aboutButton.addEventListener(MouseEvent.CLICK, handleAboutButtonClick);
			view.eventsButton.addEventListener(MouseEvent.CLICK, handleEventsButtonClick);
			view.mapButton.addEventListener(MouseEvent.CLICK, handleMapButtonClick);
		}
		
		// #endregion Constructor
		
		
		private function handleAboutButtonClick(evt:MouseEvent):void
		{
			sendNotification(Constants.SHOW_ABOUT);
		}
		
		private function handleEventsButtonClick(evt:MouseEvent):void
		{
			sendNotification(Constants.SHOW_EVENT_LIST);
		}
		
		private function handleMapButtonClick(evt:MouseEvent):void
		{
			sendNotification(Constants.SHOW_MAP);
		}
		
		private function get view():HomeView
		{
			return viewComponent as HomeView;
		}
	}
}